<% content_for :head do %>
  <%= javascript_include_tag "/assets/ckeditor/ckeditor.js" %>
<% end %>

<%= form_for [:admin, category], :url => category.new_record? ? admin_category_group_categories_path(params[:category_group_id]) : admin_category_group_category_path(params[:category_group_id]) , :validate => true do |f| %>

  <%= render "shared/error_messages", :target => category %>

  <%= f.hidden_field :category_group_id, :value => params[:category_group_id] %>
  <table>
    <tfoot>
      <tr>
        <th><%= f.submit %></th>
      </tr>
    </tfoot>
    <tbody>
      <tr>
        <th><%= f.label :presentation %></th>
        <td><%= f.text_field :presentation, :maxlength => 30, :onkeyup => "getElementById('category_url').value = make_url(this.value);" %></td>
      </tr>
      <tr>
        <th><%= f.label :url %></th>
        <td><%= f.text_field :url, :maxlength => 30 %></td>
      </tr>
      <tr>
        <th><%= f.label :headline %></th>
        <td><%= f.text_field :headline, :maxlength => 60, :size => 40 %></td>
      </tr>
      <tr>
        <th><%= f.label :title %></th>
        <td><%= f.text_field :title, :maxlength => 250, :size => 100 %></td>
      </tr>
      <tr>
        <th><%# f.label :parent_id %></th>
        <td><%# f.select :parent_id, grouped_options_for_select(CategoryGroup.all.map {|cg|
                  [cg.presentation, cg.root.self_and_descendants.map {|c| s = ""; c.level.to_i.times {s << '--'}; ["#{s} #{c.presentation}", "#{c.id}"]}]}, f.object.parent_id),
                {}, {:style => "width: 300px;"}
            %></td>
      </tr>
      <tr>
        <th><%= f.label :listing_type %></th>
        <td><%= f.select :listing_type, options_for_select({"#{t 'enumerations.category.listing_type.with_images'}" => "with_images", "#{t 'enumerations.category.listing_type.table'}" => "table"}, f.object.listing_type) %></td>
      </tr>
      <tr>
        <th><%= f.label :hidden %></th>
        <td><%= f.check_box :hidden %></td>
      </tr>
      <tr>
        <th><%= f.label :description %></th>
        <td><%= f.cktext_area :description, :width => "550px;", :height => "150px;" %></td>
      </tr>
      <%= f.fields_for :icon do |icon| %>
      <tr>
        <th><%= icon.label :attachment_file_name %></th>
        <td><%= icon.file_field :attachment %></td>
      </tr>
      <% end %>
    </tbody>
  </table>
<% end %>